from rest_framework.response import Response
from rest_framework.pagination import PageNumberPagination


class CustomPagination(PageNumberPagination):
    page_size = 12  # 每页显示的默认数量
    page_size_query_param = 'page_size'  # 可以让客户端通过查询参数动态调整每页数量

    def get_paginated_response(self, data):
        return Response({
            # 'links': {
            #     'next': self.get_next_link(),
            #     'previous': self.get_previous_link()
            # },
            'count': self.page.paginator.count,
            'current_page': self.page.number,
            # 'page_size': self.page_size,
            'total_pages': self.page.paginator.num_pages,
            'results': data,
        })
